//
//  ZhuangCheNoticeAlertView.m
//  DriverClient
//
//  Created by 吕晶 on 2020/9/10.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ZhuangCheNoticeAlertView.h"

@interface ZhuangCheNoticeAlertView ()

@property (nonatomic, strong) UIView *bgView;

@end

@implementation ZhuangCheNoticeAlertView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ScreenW, ScreenH);
        self.backgroundColor = HexColorA(0x000000, 0.5);
//        UIButton *btn = [[UIButton alloc] initWithFrame:self.frame];
//        [btn addTarget:self action:@selector(disMissView) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btn];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(30, (ScreenH - 172) * 0.5, ScreenW - 60, 172)];
    self.bgView.backgroundColor = HexColor(0xffffff);
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 6;
    [self addSubview:self.bgView];
    
    UIImageView *iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 25, 16, 16)];
    iconImgView.image = [UIImage imageNamed:@"zhuangChe_notice"];
    [self.bgView addSubview:iconImgView];
    
    UILabel *lab = [UILabel new];
    lab.textColor = HexColor(0x2B2C44);
    lab.font = BoldFontOfSize(18);
    lab.text = @"警告";
    [lab sizeToFit];
    lab.nim_left = iconImgView.nim_right + 5;
    lab.nim_centerY = iconImgView.nim_centerY;
    [self.bgView addSubview:lab];
    
    UILabel *descLab = [UILabel new];
    descLab.textColor = HexColor(0x9C9DB3);
    descLab.font = [UIFont systemFontOfSize:16];
    descLab.nim_width = self.bgView.nim_width - 40;
    descLab.text = @"装车清单与分配的货物清单不一致，提交后需要审核通过后生效。";
    descLab.numberOfLines = 0;
    [descLab sizeToFit];
    descLab.nim_left = iconImgView.nim_left;
    descLab.nim_top = iconImgView.nim_bottom + 14;
    descLab.nim_width = self.bgView.nim_width - 40;
    [self.bgView addSubview:descLab];
    
    UIButton *cancleBtn = [UIButton new];
    cancleBtn.nim_left = 0;
    cancleBtn.nim_width = (self.bgView.nim_width - 1) * 0.5;
    cancleBtn.nim_height = 50;
    cancleBtn.nim_top = self.bgView.nim_height - cancleBtn.nim_height;
    [cancleBtn setTitle:@"取消" forState:0];
    [cancleBtn setTitleColor:HexColor(0x585974) forState:0];
    cancleBtn.titleLabel.font = BoldFontOfSize(16);
    [cancleBtn addTarget:self action:@selector(disMissView) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:cancleBtn];
    
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(cancleBtn.nim_right, cancleBtn.nim_top, 1, cancleBtn.nim_height)];
    line1.backgroundColor = Color_backgroundColor;
    [self.bgView addSubview:line1];
    
    UIButton *sureBtn = [UIButton new];
    sureBtn.nim_left = line1.nim_right;
    sureBtn.nim_width = (self.bgView.nim_width - 1) * 0.5;
    sureBtn.nim_height = 50;
    sureBtn.nim_top = self.bgView.nim_height - cancleBtn.nim_height;
    [sureBtn setTitle:@"提交" forState:0];
    [sureBtn setTitleColor:Color_ThemeColor forState:0];
    sureBtn.titleLabel.font = BoldFontOfSize(16);
    [sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:sureBtn];
    
    UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(0, cancleBtn.nim_top - 1, self.bgView.nim_width, 1)];
    line2.backgroundColor = Color_backgroundColor;
    [self.bgView addSubview:line2];
}

- (void)sureClick {
    if (self.sureBlock) {
        self.sureBlock();
    }
    [self disMissView];
}

- (void)showInView:(UIView *)view {
    if (!view) {
        return;
    }
    [view addSubview:self];
    [view addSubview:self.bgView];
}

- (void)disMissView {
    [self removeFromSuperview];
    [self.bgView removeFromSuperview];
}

@end
